package btp

import "duanju-mq/pkg/log"

type fieldInfo struct {
	id    byte
	dtype DataType
	name  string
}

var (
	fieldById   = map[byte]*fieldInfo{}
	fieldByName = map[string]*fieldInfo{}
)

func AddFieldInfo(id byte, dtype DataType, name string) {
	fi := &fieldInfo{id: id, dtype: dtype, name: name}
	if _, ok := fieldById[fi.id]; ok {
		log.Fatal("duplicated id", fi.id)
	}
	fieldById[fi.id] = fi
	if _, ok := fieldByName[fi.name]; ok {
		log.Fatal("duplicated name", fi.name)
	}
	fieldByName[fi.name] = fi
}

func getFieldByName(name string) *fieldInfo {
	return fieldByName[name]
}

func getFieldById(id byte) *fieldInfo {
	return fieldById[id]
}
